package com.newtouch.bxzs.policy.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.policy.config.MyLog;
import com.newtouch.bxzs.policy.model.bo.*;
import com.newtouch.bxzs.policy.model.vo.*;
import com.newtouch.bxzs.policy.service.PolicyService;
import com.newtouch.bxzs.policy.util.PolicyListPageUtils;
import com.newtouch.bxzs.policy.util.QueryCriteriaUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 保单管理controller层
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 10:12</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "个人保单管理")
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/policy")
public class PolicyController {
    /** 静态变量：系统日志 */
    private static final Log logger = LogFactory.getLog(PolicyController.class);

    @Resource
    private PolicyService policyService;

    @ApiOperation(value = "查询个人保单列表")
    @PostMapping("/getIndividualPolicyList")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getIndividualPolicyList",userOperationType = 4,userOperationSummary = "查询个人保单列表")
    public BaseResponse<PolicyListBO> individualPolicyList(@RequestBody PolicyVO policyVO) {
        logger.info("查询个人保单列表");
       return RespGenerator.returnOK(policyService.getIndividualPolicyList(policyVO));
    }

    @ApiOperation(value = "根据保单号调用外部接口查询个人保单详情")
    @PostMapping("/getIndividualPolicyInfo")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getIndividualPolicyInfo",userOperationType = 4,userOperationSummary = "查询个人保单详情")
    public BaseResponse<PolicyBO> individualPolicyInfo(@RequestBody PolicyInfoVO policyInfoVO) {
        logger.info("查询个人保单详情");
        return RespGenerator.returnOK(policyService.getIndividualPolicyInfo(policyInfoVO));
    }

    @ApiOperation(value = "根据保单号调用外部接口查询个人保全信息")
    @PostMapping(value = "/getIndividualPolicyPreservation")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getIndividualPolicyPreservation",userOperationType = 4,userOperationSummary = "查询个单保全信息")
    public BaseResponse<PreservationBO> individualPolicyPreservation(@RequestBody PolicyInfoPageVO policyInfoPageVO) {
        logger.info("调用查询个人保全信息外部接口");
        List<PreservationBO> preservationListBO = policyService.getPolicyPreservation(policyInfoPageVO);
        if(!CollectionUtil.isEmpty(preservationListBO)){
            //对获取的保全信息进行分页处理
            PolicyListPageUtils<PreservationBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(preservationListBO,policyInfoPageVO.getPageSize(),policyInfoPageVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(preservationListBO);
    }

    @ApiOperation(value = "根据保单号调用外部接口查询个人理赔信息")
    @PostMapping(value = "/getIndividualPolicyClaims")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getIndividualPolicyClaims",userOperationType = 4,userOperationSummary = "查询个单理赔信息")
    public BaseResponse<ClaimsBO> individualPolicyClaims(@RequestBody PolicyInfoPageVO policyInfoPageVO) {
        logger.info("调用查询个人理赔信息外部接口");
        List<ClaimsBO> claimsListBO = policyService.getPolicyClaims(policyInfoPageVO);
        if(!CollectionUtil.isEmpty(claimsListBO)){
            //对获取的理赔信息进行分页处理
            PolicyListPageUtils<ClaimsBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(claimsListBO,policyInfoPageVO.getPageSize(),policyInfoPageVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(claimsListBO);
    }

    @ApiOperation(value = "查询个单保全进度列表")
    @PostMapping(value = "/getPreservationList")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getPreservationList",userOperationType = 4,userOperationSummary = "查询个单保全进度列表")
    public BaseResponse<PreservationProgressListBO> preservationList(@RequestBody PreservationVO preservationVO) {
        logger.info("查询个单保全进度列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(preservationVO.getApplicationStartDate(),preservationVO.getApplicationDeadline());
        List<PreservationProgressListBO> preservationProgressListBO = policyService.getPreservationProgressList(preservationVO);
        if(!CollectionUtil.isEmpty(preservationProgressListBO)){
            //对获取的保全进度列表信息进行分页处理
            PolicyListPageUtils<PreservationProgressListBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(preservationProgressListBO,preservationVO.getPageSize(),preservationVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(preservationProgressListBO);
    }

    @ApiOperation(value = "查看个单保全进度详情")
    @PostMapping(value = "/getPreservationInfo")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getPreservationInfo",userOperationType = 4,userOperationSummary = "查看个单保全进度详情")
    public BaseResponse<PreservationProgressInfoBO> preservationInfo(@RequestBody PreservationProgressInfoVO preservationProgressInfoVO) {
        logger.info("查看个单保全进度详情");
        return RespGenerator.returnOK(policyService.getPreservationProgressInfo(preservationProgressInfoVO));
    }

    @ApiOperation(value = "查询个单理赔进度列表")
    @PostMapping(value = "/getClaimsProgressList")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getClaimsProgressList",userOperationType = 4,userOperationSummary = "查询个单理赔进度列表")
    public BaseResponse<ClaimsProgressListBO> claimsProgressList(@RequestBody ClaimsVO claimsVO) {
        logger.info("查询个单理赔进度列表");
        List<ClaimsProgressListBO> claimsProgressListBO = policyService.getClaimsProgressList(claimsVO);
        if(!CollectionUtil.isEmpty(claimsProgressListBO)){
            //对获取的理赔进度信息进行分页处理
            PolicyListPageUtils<ClaimsProgressListBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(claimsProgressListBO,claimsVO.getPageSize(),claimsVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(claimsProgressListBO);
    }

    @ApiOperation(value = "查看个单新契约详情")
    @PostMapping(value = "/getPolicyNewContractInfo")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getPolicyNewContractInfo",userOperationType = 4,userOperationSummary = "查看个单新契约详情")
    public BaseResponse<PolicyNewContractInfoBO> policyNewContractInfo(@RequestBody PolicyNewContractInfoVO policyNewContractInfoVO) {
        logger.info("查看个单新契约详情");
        return RespGenerator.returnOK(policyService.getPolicyNewContractInfo(policyNewContractInfoVO));
    }

    @ApiOperation(value = "查询个单新契约列表")
    @PostMapping(value = "/getPolicyNewContractList")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getPolicyNewContractList",userOperationType = 4,userOperationSummary = "查询个单新契约列表")
    public BaseResponse<PolicyNewContractListBO> policyNewContractList(@RequestBody PolicyNewContractVO policyNewContractVO) {
        logger.info("查询个单新契约列表");
        List<PolicyNewContractListBO> policyNewContractListBO = policyService.getPolicyNewContractList(policyNewContractVO);
        if(!CollectionUtil.isEmpty(policyNewContractListBO)){
            //对获取的新契约保单信息进行分页处理
            PolicyListPageUtils<PolicyNewContractListBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(policyNewContractListBO,policyNewContractVO.getPageSize(),policyNewContractVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(policyNewContractListBO);
    }

    @ApiOperation(value = "查询个单满期列表")
    @PostMapping(value = "/getExpirationPolicyList")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getExpirationPolicyList",userOperationType = 4,userOperationSummary = "查询个单满期列表")
    public BaseResponse<ExpirationPolicyBO> expirationPolicyList(@RequestBody ExpirationPolicyVO expirationPolicyVO) {
        logger.info("查询个单满期信息列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(expirationPolicyVO.getExpirationStartDate(),expirationPolicyVO.getExpirationDeadline());
        List<ExpirationPolicyBO> expirationPolicyBO = policyService.getExpirationPolicyList(expirationPolicyVO);
        if(!CollectionUtil.isEmpty(expirationPolicyBO)){
            //对获取的满期数据进行分页处理
            PolicyListPageUtils<ExpirationPolicyBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(expirationPolicyBO,expirationPolicyVO.getPageSize(),expirationPolicyVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(expirationPolicyBO);
    }

    @ApiOperation(value = "查询个单续期列表")
    @PostMapping(value = "/getRenewalPolicyList")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getRenewalPolicyList",userOperationType = 4,userOperationSummary = "查询个单续期列表")
    public BaseResponse<RenewalPolicyListBO> renewalPolicyList(@RequestBody RenewalPolicyVO renewalPolicyVO) {
        logger.info("查询个单续期信息列表");
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(renewalPolicyVO.getPaymentStartDate(),renewalPolicyVO.getPaymentDeadline());
        List<RenewalPolicyListBO> renewalPolicyListBO = policyService.getRenewalPolicyList(renewalPolicyVO);
        if(!CollectionUtil.isEmpty(renewalPolicyListBO)){
            PolicyListPageUtils<RenewalPolicyListBO> list=new PolicyListPageUtils<>();
            return RespGenerator.returnOK(list.policyListByPage(renewalPolicyListBO,renewalPolicyVO.getPageSize(),renewalPolicyVO.getCurrentPage()));
        }
        return RespGenerator.returnOK(renewalPolicyListBO);
    }
    @ApiOperation(value = "通知跳转个单满期列表")
    @PostMapping(value = "/getExpirationPolicyListNotice")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getExpirationPolicyListNotice",userOperationType = 4,userOperationSummary = "通知跳转个单满期列表")
    public BaseResponse<ExpirationPolicyBO> expirationPolicyListNotice(@RequestBody ExpirationPolicyVO expirationPolicyVO) {
        logger.info("通知跳转个单满期列表");
        return RespGenerator.returnOK(policyService.getExpirationPolicyList(expirationPolicyVO));
    }

    @ApiOperation(value = "通知跳转个单保全列表")
    @PostMapping(value = "/getPreservationListNotice")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getPreservationListNotice",userOperationType = 4,userOperationSummary = "通知跳转保全列表")
    public BaseResponse<PreservationProgressListBO> getPreservationListNotice(@RequestBody PreservationVO preservationVO) {
        logger.info("通知跳转保全列表");
        return RespGenerator.returnOK(policyService.getPreservationProgressList(preservationVO));
    }

    @ApiOperation(value = "通知跳转个单续期列表")
    @PostMapping(value = "/getRenewalPolicyListNotice")
    @MyLog(systemFunctionName = "个人保单管理",systemFunctionUrl = "/policy/getRenewalPolicyListNotice",userOperationType = 4,userOperationSummary = "通知跳转个单续期列表")
    public BaseResponse<RenewalPolicyListBO> renewalPolicyListNotice(@RequestBody RenewalPolicyVO renewalPolicyVO) {
        logger.info("通知跳转个单续期列表");
        return RespGenerator.returnOK(policyService.getRenewalPolicyList(renewalPolicyVO));
    }
}
